<template>
    <div>
        <el-row type="flex" class="attachment" v-if="!isMultiple">
            <el-col :span="7">
                <span class="icon" :title="fileObj.fileName">{{ fileObj.fileName }}</span>
                <a @click="downloadFile(fileObj.fileId)" class="color-primary">下载</a>
                <a @click="removeFile" v-show="showClose"><i class="el-icon-close" /></a>
            </el-col>
        </el-row>
        <!-- 多个附件 -->
        <div v-else>
            <el-row
                type="flex"
                class="attachment"
                v-for="(item, index) in fileObjList"
                :key="item.fileId"
            >
                <el-col :span="7">
                    <span class="icon" :title="item.fileName">{{ item.fileName }}</span>
                    <a @click="downloadFile(item.fileId)" class="color-primary">下载</a>
                    <a @click="removeFileItem(index, item.fileId)" v-show="showClose">
                        <i class="el-icon-close" />
                    </a>
                </el-col>
            </el-row>
        </div>
    </div>
</template>

<script>
import condType from '@/api/condType';

export default {
    name: 'fileListWhite',
    props: {
        showClose: {
            default: false,
            type: Boolean,
        },
        fileObj: {
            default: () => {},
            type: Object,
        },
        // 多个附件存在时
        fileObjList: {
            default: () => [],
            type: Array,
        },
        // 是否上传多文件
        isMultiple: {
            type: Boolean,
            default: false,
        },
    },
    data() {
        return {};
    },
    methods: {
        downloadFile(id) {
            // this.$emit()
            condType.downLoadFile(id);
            // condType.downloadFileByNotLogin(id);
        },
        removeFile() {
            this.$emit('removeFile');
        },
        // 多个附件时 删除附件
        removeFileItem(index, fileId) {
            this.$emit('removeFileItem', index, fileId);
        },
    },
};
</script>
<style scoped>
.attachment {
    flex-wrap: wrap;
    box-sizing: border-box;
}
.attachment .el-col {
    font-size: 14px;
    width: 260px;
    height: 36px;
    line-height: 36px;
    border-radius: 5px;
    box-sizing: border-box;
    display: flex;
    margin-right: 10px;
    margin-bottom: 5px;
    justify-content: space-around;
    background: #fff;
    box-shadow: 0px 1px 8px 0px rgba(0, 0, 0, 0.05);
}
.attachment .icon {
    position: relative;
    white-space: nowrap;
    text-overflow: ellipsis;
    overflow: hidden;
    width: 180px;
    margin-left: 25px;
}

.attachment .el-col::after {
    content: ' ';
    width: 16px;
    height: 18px;
    display: inline-block;
    margin-right: 5px;
    background: url(./attachment.png);
    background-size: contain;
    position: absolute;
    top: 10px;
    left: 10px;
}
</style>
